﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using WangYiYunWPF.Common;
using WangYiYunWPF.Models;

namespace WangYiYunWPF.ViewModels
{
    public class MainWindowViewModel
    {
        private static MainWindowViewModel mainWindowViewModel = new MainWindowViewModel();
        public static MainWindowViewModel GetInstance()
        {
            return mainWindowViewModel;
        }
        public MainWindowModel Model { get; set; }

        public MainWindow MainWindow { get; set; }

        //缩小
        public CommandBase ZoomOutWindowButCommand { get; set; }
        //最大化
        public CommandBase ZoomWindowButCommand { get; set; }
        //关闭
        public CommandBase CloseWindowButCommand { get; set; }
        public MainWindowViewModel()
        {
            MainWindow = MainWindow.mainWindow;
            Model = new MainWindowModel();

            //缩小
            ZoomOutWindowButCommand = new CommandBase();
            ZoomOutWindowButCommand.DoExecute = new Action<object>((o) =>
            {
                MainWindow.WindowState = WindowState.Minimized;
            });
            ZoomOutWindowButCommand.DoCanExecute = new Func<object, bool>((o) => { return true; });

            //最大化
            ZoomWindowButCommand = new CommandBase();
            ZoomWindowButCommand.DoExecute = new Action<object>((o) => ZoomWindow());
            ZoomWindowButCommand.DoCanExecute = new Func<object, bool>((o) => { return true; });

            //关闭应用
            CloseWindowButCommand = new CommandBase();
            CloseWindowButCommand.DoExecute = new Action<object>((o) =>
            {
                MainWindow.Visibility = Visibility.Collapsed;
            });
            CloseWindowButCommand.DoCanExecute = new Func<object, bool>((o) => { return true; });
        }        

        /// <summary>
        /// 最大化\还原
        /// </summary>
        public void ZoomWindow()
        {
            //判断是否以及最大化，最大化就还原窗口，否则最大化
            if (MainWindow.WindowState == WindowState.Maximized)
            {
                MainWindow.WindowState = WindowState.Normal;
                Model.ZoomWindowButContent = "\xe65d";
            }
            else
            {
                MainWindow.WindowState = WindowState.Maximized;
                Model.ZoomWindowButContent = "\xe653";
            }
        }
    }
}
